package javatest.algorith;

/*
 * 汉诺塔
 */
public class Hanoi {
    
    public void process(int n){
        System.out.println("n = " + n );
        move(n, "左", "右", "中");
    }
    private void move(int i, String from, String to, String other){
        if (i==1) print(i, from, to);
        else{
            move(i-1, from, other, to);
            print(i, from, to);
            move(i-1, other, to, from);
        }
    }
    private void print(int i, String from, String to){
        System.out.println("Move "+ i + " "+ from + " -> " + to);
    }
    public static void main(String[] args) {
        Hanoi h = new Hanoi();
        int n = 3;
        h.process(n);
    }
}
